home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / ipdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.8 KB  |  88 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9. #include "netuser.h"
  10. #include "config.h"
  11.  
  12. void
  13. ip_dump(fp,bpp,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     struct ip ip;
  19.     int16 ip_len;
  20.     int16 length;
  21.     int16 csum;
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;    
  25.  
  26.     fprintf(fp,"IP:");
  27.     /* Sneak peek at IP header and find length */
  28.     ip_len = ((*bpp)->data[0] & 0xf) << 2;
  29.     if(ip_len < IPLEN){
  30.         fprintf(fp," bad header\n");
  31.         return;
  32.     }
  33.     if(check)
  34.         csum = cksum(NULLHEADER,*bpp,ip_len);
  35.     else
  36.         csum = 0;
  37.  
  38.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  39.  
  40.     /* Trim data segment if necessary. */
  41.     length = ip.length - ip_len;    /* Length of data portion */
  42.     trim_mbuf(bpp,length);    
  43.     fprintf(fp," len %u",ip.length);
  44.     fprintf(fp," %s",inet_ntoa(ip.source));
  45.     fprintf(fp,"->%s ihl %u ttl %u",
  46.         inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  47.     if(ip.tos != 0)
  48.         fprintf(fp," tos %u",uchar(ip.tos));
  49.     if(ip.offset != 0 || ip.flags.mf)
  50.         fprintf(fp," id %u offs %u",ip.id,ip.offset);
  51.     if(ip.flags.df)
  52.         fprintf(fp," DF");
  53.     if(ip.flags.mf){
  54.         fprintf(fp," MF");
  55.         check = 0;    /* Bypass host-level checksum verify */
  56.     }
  57.     if(csum != 0)
  58.         fprintf(fp,"\nIP: CHECKSUM ERROR (%u)",csum);
  59.  
  60.     if(ip.offset != 0){
  61.         fputc('\n',fp);
  62.         return;
  63.     }
  64.     switch(uchar(ip.protocol)){
  65.     case TCP_PTCL:
  66.         fprintf(fp," prot TCP\n");
  67.         tcp_dump(fp,bpp,ip.source,ip.dest,check);
  68.         break;
  69.     case UDP_PTCL:
  70.         fprintf(fp," prot UDP\n");
  71.         udp_dump(fp,bpp,ip.source,ip.dest,check);
  72.         break;
  73.     case ICMP_PTCL:
  74.         fprintf(fp," prot ICMP\n");
  75.         icmp_dump(fp,bpp,ip.source,ip.dest,check);
  76.         break;
  77. #ifdef    RSPF
  78.     case RSPF_PTCL:
  79.         fprintf(fp," prot RSPF\n");
  80.         rspf_dump(fp,bpp,ip.source,ip.dest,check);
  81.         break;
  82. #endif    /* RSPF */
  83.     default:
  84.         fprintf(fp," prot %u\n",uchar(ip.protocol));
  85.         break;
  86.     }
  87. }
  88.